#pragma once

#include <funcc.h>
#include <log4cpp/Category.hh>
#include <log4cpp/OstreamAppender.hh>
#include <log4cpp/FileAppender.hh>
#include <log4cpp/RollingFileAppender.hh>
#include <log4cpp/PatternLayout.hh>
#include <log4cpp/Priority.hh>

#define LogInfo(msg) (Mylogger::getInstance()->info(\
    string(" ") + __FILE__ + " " + __func__ + " " + to_string(__LINE__) + " : " + msg\
))
#define LogError(msg) (Mylogger::getInstance()->error(\
    string(__FILE__) + " " + __func__ + " " + to_string(__LINE__) + " : " + msg\
))
#define LogWarn(msg) (Mylogger::getInstance()->warn(\
    string(" ") + __FILE__ + " " + __func__ + " " + to_string(__LINE__) + " : " + msg\
))
#define LogDebug(msg) (Mylogger::getInstance()->debug(\
    string(__FILE__) + " " + __func__ + " " + to_string(__LINE__) + " : " + msg\
))

using namespace std;
using namespace log4cpp;

class Mylogger
{
public:
    static Mylogger* getInstance();
    static void destory();

    Mylogger(const Mylogger &) = delete;
    Mylogger & operator=(const Mylogger &) = delete;

    void warn(string msg);
    void error(string msg);
    void debug(string msg);
    void info(string msg);
    void fatal(string msg);
    void crit(string msg);
    
private:
    Mylogger();
    ~Mylogger();
    
private:
    Category& _log;
    static Mylogger * _pInstance; // 指向Mylogger对象
    //数据成员,最核心的是Categoty，其他的都是从Category出发的
    // 因此可以只把Categroy作为数据成员，其他模块在构造函数中进行初始化
};